﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace MINERP.BLL.Statistics
{
    public class ShopNoPayBLL
    {
        //参数
        private DAL.Statistics.ShopNoPayDAL dal = new MINERP.DAL.Statistics.ShopNoPayDAL();

        #region 商户列表
        /// <summary>
        /// 商户列表
        /// </summary>
        /// <returns></returns>
        public List<ShopCL> GetShopList()
        {
            try
            {
                DataTable dt = dal.GetShopList();
                List<ShopCL> shops = new List<ShopCL>();
                foreach (DataRow r in dt.Rows)
                {
                    ShopCL shop = new ShopCL();
                    if (r["Area"] != DBNull.Value && r["Area"].ToString().Length > 0)
                    {
                        shop.Area = r["Area"].ToString();
                    }
                    else
                    {
                        shop.Area = "未分配地区";
                    }
                    shop.ShopId = Convert.ToInt32(r["ShopId"]);
                    shop.ShopName = r["ShopName"].ToString();
                    shops.Add(shop);
                }
                shops = shops.OrderBy(p => p.ShopName).ToList();
                return shops;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region 商户欠款统计
        /// <summary>
        /// 商户欠款统计
        /// </summary>
        public DataTable GetShopNoPay(List<int> shopIds, int startYear, int endYear, int startMonth, int endMonth, int noPayMoneyStatus)
        {
            try
            {
                DataTable dt = dal.GetShopNoPay(shopIds, startYear, endYear, startMonth, endMonth, noPayMoneyStatus);
                return dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public DataTable GetShopNoPay(List<int> shopIds, DateTime startTime,DateTime endTime, int noPayMoneyStatus)
        {
            try
            {
                DataTable dt = dal.GetShopNoPay(shopIds, startTime,endTime, noPayMoneyStatus);
                return dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        //---------------数据结构-------------
        public class ShopCL
        {
            public int ShopId { get; set; }
            public string ShopName { get; set; }
            public string Area { get; set; }
        }
        /// <summary>
        /// 时间范围的dt
        /// </summary>
        /// <returns></returns>
        public DataTable CreateTimeDt()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("StartTime", typeof(string));
            dt.Columns.Add("EndTime", typeof(string));
            return dt;
        }
    }
}
